package ${package.Controller};

import com.diaohw.platform.common.obj.page.PageResultVo;
import com.diaohw.platform.common.validator.InsertGroup;
import com.diaohw.platform.common.validator.UpdateGroup;
import ${package.Dto}.${dto};
import ${package.queryPkg}.${query};
import ${package.Vo}.${vo};
import ${package.Service}.${table.serviceName};
import io.swagger.v3.oas.annotations.Operation;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.*;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.List;
/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Tag(name = "${table.comment!}")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen?replace("-do","")}<#else>${table.entityPath?replace("-do","")}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>

    @Resource
    private ${table.serviceName} service;

    @PostMapping
    @Operation(summary = "新增")
    public ${vo} create(@RequestBody @Validated(InsertGroup.class) ${dto} data) {
        return service.create(data);
    }

    @PutMapping("/{id}")
    @Operation(summary = "更新")
    public ${vo} update(@PathVariable("id") String id, @RequestBody @Validated(UpdateGroup.class) ${dto} data) {
        return service.update(id, data);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "依据ID查看删除")
    public Boolean delete(@PathVariable("id") String id) {
        return service.delete(id);
    }

    @DeleteMapping
    @Operation(summary = "依据查询条件删除")
    public Boolean delete(@RequestBody ${query} query) {
        return service.delete(data);
    }

    @GetMapping("/{id}")
    @Operation(summary = "依据ID查看信息")
    public ${vo} detail(@PathVariable("id") String id) {
        return service.detail(id);
    }

    @GetMapping
    @Operation(summary = "查询列表")
    public List<${vo}> all(${query} query) {
        return service.findByList(query);
    }

    @GetMapping("/page")
    @Operation(summary = "分页查看")
    public PageResultVo<${vo}> page(${query} query) {
        return service.findByPage(query);
    }

}
</#if>
